typedef struct tdTPM_SEALED_DATA 
{ 
TPM_PAYLOAD_TYPE payload; 
TPM_SECRET authData; 
TPM_NONCE tpmProof; 
TPM_DIGEST storedDigest; 
UINT32 dataSize; 
BYTE *data; 
} TPM_SEALED_DATA; 
 
int MyFunc_SealData(TSS_HKEY hKey, TSS_HPCRS hPcrs, UINT32 in_size, BYTE *in, UINT32 *out_size, BYTE *out) 
{ 
TSS_HENCDATA hEncData; 
UINT32 keySize, tmp_out_size; 
BYTE *tmp_out; 
/* Create the encrypted data object in the TSP */ 
Tspi_Context_CreateObject(hContext, 
TSS_OBJECT_TYPE_ENCDATA, 
TSS_ENCDATA_SEAL, &hEncData ); 
Tspi_GetAttribUint32(hKey, TSS_TSPATTRIB_KEY_INFO, 
TSS_TSPATTRIB_KEYINFO_SIZE, &keySize); 
/* Make sure the data is small enough to be bound by this key,taking into account the OAEP padding size (38) and  the size of the TPM_SEALED_DATA structure (65) */ if (in_size > keySize – 103) { 
LogError(“Data to be encrypted is too big!”); return -1; 
} 
Tspi_Data_Seal(hEncData, hKey, in_size, in, hPcrs); 
/* Now hEncData contains an encrypted blob, let’s extract it */ 
Tspi_GetAttribData(hEncData, TSS_TSPATTRIB_ENCDATA_BLOB, TSS_TSPATTRIB_ENCDATABLOB_BLOB,&tmp_out_size, &tmp_out); if (tmp_out_size > *out_size) { 
LogError(“Encrypted data blob is too big!”); return -1; 
} 
/* Copy the encrypted data blob to the user’s buffer */ 
memcpy(out, tmp_out, tmp_out_size); *out_size = tmp_out_size; 
/* Free the blob returned by the TSP */ 
Tspi_Context_FreeMemory( hContext, tmp_out); 
/* Close the encrypted data object, it will no longer be used */ Tspi_Context_CloseObject( hContext, hEncData); return 0; 
} 